<?php
/**
 * 后台菜单模型
 * User 1874
 */
namespace app\adminplatform\model; 
use think\facade\Request; 
use think\Model;

class BackMenu extends Model{ 
    /**
     * 获取BackMenu分页
     */
    public static function getBackMenuPage(array $map=[]){
        return BackMenu::where($map)->paginate(['list_rows'=>PageNum,'query'=>Request::param()]);
    }
    /**
     * 获取BackMenu列表
     */
    public static function getBackMenuList(array $map=[]){
        return BackMenu::where($map)->order("bm_sort Asc")->select();
    }
    /**
     * 获取BackMenu详情
     */
    public static function getBackMenuDetail(array $map=[]){
        return BackMenu::where($map)->find();
    }
    /**
     * 递归子菜单重组数据
     * @param array $menu 菜单数据
     * @param int $pid 父id
     * @return array
     */
    public static function getBackMenuChild(array $menu, int $pid=0){
        $array = [];
        foreach ($menu as $key => $value){
            if ($value["bm_pid"] == $pid){
                $data = [];
                $data['title'] = $value["bm_title"];
                $data['rulesId'] = $value["bm_rulesId"];
                $data['status'] = $value["bm_status"];
                if(!empty($value["bm_url"])) $data['url'] = $value["bm_url"];
                if(!empty($value["bm_icon"])) $data['icon'] = $value["bm_icon"];
                $data['child'] = self::getBackMenuChild($menu, $value["bm_id"]);
                $array[] = $data;
            }
        }
        return $array;
    }
}